package com.hongyuan.sellfitness.ui.person.view_mode;

import android.app.Application;
import android.os.Bundle;
import android.util.Log;

import androidx.annotation.NonNull;
import androidx.databinding.ObservableField;

import com.hongyuan.mvvmhabitx.binding.command.BindingAction;
import com.hongyuan.mvvmhabitx.binding.command.BindingCommand;
import com.hongyuan.sellfitness.base.Constants;
import com.hongyuan.sellfitness.base.CustomViewModel;
import com.hongyuan.sellfitness.data.MyRepository;
import com.hongyuan.sellfitness.ui.home.activity.MyMemberCardActivity;
import com.hongyuan.sellfitness.ui.person.activity.CourseRecordActivity;
import com.hongyuan.sellfitness.ui.person.activity.MyCouponActivity;
import com.hongyuan.sellfitness.ui.person.activity.MyLessionActivity;
import com.hongyuan.sellfitness.ui.person.activity.MyOrdersActivity;
import com.hongyuan.sellfitness.ui.person.activity.MyReservationActivity;
import com.hongyuan.sellfitness.ui.person.activity.SettingActivity;
import com.hongyuan.sellfitness.ui.person.activity.UserInfoActivity;
import com.hongyuan.sellfitness.ui.person.beans.KeFuBean;
import com.hongyuan.sellfitness.ui.person.beans.PersonBean;

public class PersonViewModel extends CustomViewModel<MyRepository> {

    public ObservableField<PersonBean.InfoBean> entity = new ObservableField<>();

    public ObservableField<KeFuBean> callKfTel = new ObservableField<>();

    public PersonViewModel(@NonNull Application application, MyRepository model) {
        super(application, model);
    }

    //个人主页
    public BindingCommand goInfo = new BindingCommand(new BindingAction() {
        @Override
        public void call() {
            Bundle bundle = new Bundle();
            bundle.putString("user_id",String.valueOf(entity.get().getM_id()));
            bundle.putString("userPhone",entity.get().getM_mobile());
            startActivity(UserInfoActivity.class,bundle);
        }
    });
    //我的会员卡
    public BindingCommand goMyCard = new BindingCommand(new BindingAction() {
        @Override
        public void call() {
            startActivity(MyMemberCardActivity.class);
        }
    });

    //我的私教课
    public BindingCommand goMyLession = new BindingCommand(new BindingAction() {
        @Override
        public void call() {
            startActivity(MyLessionActivity.class);
        }
    });

    //我的预约
    public BindingCommand goMyReservation = new BindingCommand(new BindingAction() {
        @Override
        public void call() {
            startActivity(MyReservationActivity.class);
        }
    });

    //我的订单
    public BindingCommand goMyOrders = new BindingCommand(new BindingAction() {
        @Override
        public void call() {
            startActivity(MyOrdersActivity.class);
        }
    });

    //我的上课记录
    public BindingCommand goRecord = new BindingCommand(new BindingAction() {
        @Override
        public void call() {
            startActivity(CourseRecordActivity.class);
        }
    });

    //我的优惠券
    public BindingCommand goMyCoupon= new BindingCommand(new BindingAction() {
        @Override
        public void call() {
            startActivity(MyCouponActivity.class);
        }
    });

    //我的客服
    public BindingCommand telKf= new BindingCommand(new BindingAction() {
        @Override
        public void call() {
            getUC().getCallTel().setValue(callKfTel.get().getInfo().getTel());
        }
    });

    //设置页面
    public BindingCommand goSetting= new BindingCommand(new BindingAction() {
        @Override
        public void call() {
            startActivity(SettingActivity.class);
        }
    });


    @Override
    protected void returnData(int code, Object dataBean) {
        super.returnData(code, dataBean);

        if(code == Constants.GET_MEMBER_INDEX_INFO){
            PersonBean.InfoBean infoBean = ((PersonBean)dataBean).getInfo();
            entity.set(infoBean);

            //获取客服电话
            clearParams().setParams("type","pt");
            requestData(Constants.GET_ONLINE_KF);
        }

        if(code == Constants.GET_ONLINE_KF){
            KeFuBean keFuBean = (KeFuBean)dataBean;
            callKfTel.set(keFuBean);
        }
    }


}
